<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['basic']=$this->plugin_setting('basic');
$return['banner']=$return['basic']['hdps'];
if($_RQ['op']=='main'){
	/*******main*******/
	//路线
	$id=$_RQ['id'];
	if(!$id){
		exi('该路线可能已下架或已删除','error');
	}
	$way=pdo_get('jy_tour_way',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	if($way){
		$images=json_decode($way['images'],true);
		$merch=pdo_get('jy_tour_merch',array('uniacid'=>$_SESSION['uniacid'],'id'=>$way['merchid']));
		$way['merch']=$merch;
		$way['images']=$images;
	}
	$return['way']=$way;
	$return['price']=pdo_getcolumn('jy_tour_way',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),'price');
	$return['suitlist']=array(0=>array('id'=>'1','minprice'=>'100','suitname'=>'套餐1'),1=>array('id'=>'2','minprice'=>'200','suitname'=>'套餐2'));
	$return['post']=array();
	$return['post']['way']=$way;
	exi($return);
}
if($_RQ['op']=='suit'){
	
		$post=get_postdata();
		$row=array();
		$row['description']='这是描述';
		$row['paytype']='全款支付';
        $out = array();
        $suitid = intval($post['param']['suitid']);
		
        $productid = intval($post['param']['productid']);
        $wayid = intval($post['wayid']);
		$day = strtotime(date('Y-m-d'));
		//最近七天
		$day2 = strtotime("+7 days", $day);
		$time=timeList($day,$day2);
		$out['useday'] = date('Y-m-d');//当前使用日期.
        $out['storage'] = 10;//库存
        $out['roombalance'] = 1;
		$out['haschild'] = 1;
		$out['childprice'] = 1;
		$out['hasprice']=1;
		
		
		
		$out['row']=$row;
		exi($out);
	//	print_r($day.'hh');exit;
  /*      $row = DB::select()->from('line_suit')->where('id','=',$suitid)->execute()->current();
        $row['description'] = Product::strip_style($row['description']);
        switch ($row['paytype'])
        {
            case 1:
                $row['paytype_name']= '全款支付';
                break;
            case 2:
                $row['paytype_name']= '定金支付';
                break;
            case 3:
                $row['paytype_name']= '二次确认';
                break;

        }
        //获取最接近当前日期的报价
        $day = strtotime(date('Y-m-d'));
        //线路提前预定
        $ext = array();
        $info = DB::select('islinebefore', 'linebefore')->from('line')->where('id', '=', $productid)->execute()->current();
        $ext['islinebefore'] = $info['islinebefore'];
        $ext['linebefore'] = $info['linebefore'];
        if ($ext['islinebefore'] > 0 && $ext['linebefore'] > 0)
        {
            $day = strtotime("+{$ext['linebefore']} days", $day);
        }
        $ar = Model_Line_Suit_Price::get_price_byday($suitid, $day);

        if ($ar[0])
        {
            $out['useday'] = date('Y-m-d', $ar[0]['day']);//当前使用日期.
            $out['storage'] = $ar[0]['number'];//库存
            $out['roombalance'] = $ar[0]['roombalance'];
        }
        $group_arr = explode(',',$ar[0]['propgroup']);
        if (in_array(1, $group_arr))
        {
            $out['haschild'] = 1;
            $out['childprice'] = $ar[0]['childprice'] ? $ar[0]['childprice'] : 0;
        }
        if (in_array(2, $group_arr))
        {
            $out['hasadult'] = 1;
            $out['adultprice'] = $ar[0]['adultprice'] ? $ar[0]['adultprice'] : 0;
        }
        if (in_array(3, $group_arr))
        {
            $out['hasold'] = 1;
            $out['oldprice'] = $ar[0]['oldprice'] ? $ar[0]['oldprice'] : 0;
        }
        $out['row'] = $row;

        $hasprice = DB::select(DB::expr('count(*) as num'))->from('line_suit_price')
            ->where('lineid','=',$productid)->and_where('suitid','=',$suitid)
            ->execute()->get('num');
        $out['hasprice']= $hasprice;
        echo json_encode($out);
		*/
}
if($_RQ['op']=='price'){
	$wayid=$_RQ['way_id'];
	$suitid=$_RQ['suitid'];
	$startdate=date('Ymd');
	$day = $startdate;
    $year = date('Y',$day);
    $month = date('m',$day);
	$wayprice=pdo_getcolumn('jy_tour_way',array('uniacid'=>$_SESSION['uniacid'],'id'=>$wayid),'price');
	$arr=array(
	 array('day'=>$day,'price'=>100),
	 array('day'=>$day+1,'price'=>200),
	 array('day'=>$day+2,'price'=>300)
	);
	for($i=0;$i<31;$i++){
		$arr[]=array('day'=>$day+$i,'price'=>$wayprice,'number'=>100);
	}
	foreach ($arr as $row)
    {
		 $price[$row['day']]['date'] = date('Y-m-d', strtotime($row['day']));
		 $price[$row['day']]['weekid'] =  $row['weekid'];
		 $price[$row['day']]['price'] =  $row['price'];
		 $price[$row['day']]['profit'] = 1;
		 $price[$row['day']]['suitid'] = $suitid;
         $price[$row['day']]['description'] = '描述';//描述
		 //已购买票数
		 $go_time=$price[$row['day']]['date'];
		 $isbuynums=pdo_getsum('jy_tour_order',array('status'=>1,'uniacid'=>$_SESSION['uniacid'],'way_id'=>$wayid,'go_time'=>$go_time),'buynum');
		 $price[$row['day']]['number'] = $row['number']-$isbuynums;//库存
	}
	$price_arr=$price;
	exi($price_arr);
}
if($_RQ['op']=='next'){
	$post=get_postdata();
	if(empty($post['data']['usedate'])){
		exi('请选择出发时间！','error');
	}
	exi('','','jy_tour/way.over_book//merchid='.$post['way']['merchid'].'&way_id='.$post['way']['id'].'&go_time='.$post['data']['usedate'].'&buynum='.$post['num'].'&price='.$post['data']['price']);
	
}